<%@ page language="java" import="java.util.*" import="goods.Goods" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

Goods[] goods=(Goods[])request.getAttribute("good");
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
<title>查看所有商品</title>
	<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
	<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
	<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
	<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
	<script type=" text/javascript">

function loadXMLDoc(){
	var xmlhttp;
	if(window.XMLHttpRequest){
		xmlhttp=new XMLHttpRequest();
	}else{
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	return xmlhttp;
}
function jump1() {
		var ajax;
		ajax = loadXMLDoc();
		ajax.open("POST", "manage_good", true);
		ajax.onreadystatechange = function() {
			if (ajax.readyState == 4 && ajax.status == 200) {
				var result = ajax.responseText;

				if (result == "2") {
					location.href = "message.jsp";
				} else if(result=="1"){
					document.getElementById("mypd").innerHTML = "请认真填写表格";
				}else{
					document.getElementById("mypd").innerHTML = "用户名已存在";
				}

			}
		}
		ajax.setRequestHeader("Content-type",
				"application/x-www-form-urlencoded");
		var username = document.getElementById("username").value;
		var pwd = document.getElementById("password").value;
		var sex=document.getElementById("male").value;
		var name = document.getElementById("password").value;
		ajax.send("username=" + username + "&password=" + pwd+"&sex=" + sex + "&name=" + name);
	}

function jump2(num) {
		var ajax;
		var row = num.parentNode.parentNode.rowIndex;

		ajax = loadXMLDoc();
		ajax.open("POST", "manage_good", true);
		var tableId = document.getElementById("goods"); 

		ajax.onreadystatechange = function() {
			if (ajax.readyState == 4 && ajax.status == 200) {
				var result = ajax.responseText;
				if(result=="false"){
					document.getElementById("goods").deleteRow(row);
				}
			}
		}
		ajax.setRequestHeader("Content-type",
				"application/x-www-form-urlencoded");
		var id=tableId.rows[row].cells[1].innerHTML;
		ajax.send("id=" + id);
	}
	</script>
</head>

<body>

<div class="panel panel-default">
	<div class="panel-heading">
		<h3 class="panel-title">超市仓库管理系统</h3>
		
	</div>
	<div class="panel-body">
		查看商品
	</div>
	<div>
		<table class="table" id="goods">
			<th>名称</th><th>编号 </th><th>数量 </th><th>价格 </th><th>类别 </th><th>货架 </th><th>修改 </th><th>删除 </th>
			<%for(int i=0;i<goods.length;i++){ %>
		<tr  id="tr<%=i%>">
			<td id="td<%=i%>"><%=goods[i].getTradename() %></td><td><%=goods[i].getProductId() %>
			</td><td><%=goods[i].getNumber() %></td><td><%=goods[i].getMoney() %></td><td><%=goods[i].getClass_() %></td><td><%=goods[i].getLocation() %></td>
			<td><button type="button" id="button<%=i %>" value="button<%=i%>" >点击修改</button></td>
			<td><button type="button" id="bt<%=i %>" value=""  onclick="jump2(this)  ">点击删除</button></td>
		</tr>
				
			<%} %>
		
		</table>
	</div>
	</div>
	<ul class="pagination">
				<li>
					 <a href="supermarket.jsp#trade.jsp">首页</a>
				</li>
				<%for(int i=0;i<=goods.length/20;i++){ %>
				<li>
					 <a href="supermarket.jsp#trade"><%=(i+1) %></a>
				</li>
				<% }%> 
				<li>
					 <a href="supermarket.jsp#trade">尾页</a>
				</li>
			</ul>
	<div>
		查询商品
	</div>	
	<form class="bs-example bs-example-form" role="form">
		<div class="row">
			<div class="col-lg-6">
				
				<div class="input-group">
					<input type="text" class="form-control">
					<span>
						<button class="btn btn-default" type="button">
							查询
						</button>
					</span>
				</div><!-- /input-group -->
			</div><!-- /.col-lg-6 -->
		</div><!-- /.row -->
	</form>
</body>
</html>
